package com.boot.controller;

import com.boot.until.Base64Until;
import com.boot.until.FileUpload;
import com.boot.until.FtpUntil;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.http.parser.MediaType;
import org.jooq.DSLContext;
import org.jooq.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static com.boot.pojo.Tables.*;
import static com.boot.pojo.Tables.HDJ_USER;
import static com.boot.until.UtilBase.dataChangeJsonArray;

@RestController
@RequestMapping("test")
@Slf4j
public class Conroller extends BaseController  {

    @Autowired
    private DSLContext create;

    @RequestMapping(value = "test",method = RequestMethod.POST,produces="application/json;charset=utf-8")
    public String test(@RequestBody String query){
        Result hdjUserRecord=create.select (  )
                .from (HDJ_USER )
                .where ( HDJ_USER.ID.eq ( 8 ) )
                .fetch();
        log.info ( "数据={},参数={}",hdjUserRecord,query );
     return success (dataChangeJsonArray ( hdjUserRecord ));
    }

    /**
     * 文件上传测试
     * @return
     */
    @RequestMapping(value = "upload",method = RequestMethod.POST,produces ="application/json;charset=utf-8")
    public String upload(@RequestBody String query,  HttpServletRequest request){
        JsonObject json=new JsonParser ().parse ( query ).getAsJsonObject ();
        String img=json.get ( "img" ).getAsString ();
        //return FileUpload.uploadBase ( img,request );
        //String path="D:\\360安全浏览器下载\\图片\\new.jpg";
        //return FileUpload.uploadBase ( img,request );
        return success (FileUpload.uploadBase ( img,request ));
    }







}
